cmake_minimum_required (VERSION 2.8)

SET(GAMESERVER_SRC main.c env.c client.c buffer.c array.c role.c game.c hashtable.c slice.c)

SET(PROGRAM_NAME gameserver)
SET(VERSION 0.0.1)

option(gameserver "Build gameserver." ON)

if (NOT INSTALL_DIR)
    SET(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/output)
else()
    SET(CMAKE_INSTALL_PREFIX ${INSTALL_DIR})
endif()

set(CMAKE_VERBOSE_MAKEFILE ON)

SET(ANET_ROOT $ENV{ANET_ROOT})
if (NOT ANET_ROOT)
    MESSAGE(FATAL_ERROR "ANET_ROOT is not exported")
endif()

MESSAGE("current platform: ${CMAKE_SYSTEM_NAME}")

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
  SET(CMAKE_C_COMPILER "/usr/bin/gcc")
  SET(CMAKE_C_FLAGS "-Wall -Werror -std=gnu99 -g")
  SET(CMAKE_CXX_COMPILER "/usr/bin/g++")
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=gnu99 -g")
else (CMAKE_SYSTEM_NAME MATCHES "Darwin")
    SET(CMAKE_C_COMPILER "clang")
    SET(CMAKE_C_FLAGS "-Wall -Werror -std=gnu99 -g")
    SET(CMAKE_CXX_COMPILER "clang++")
    SET(CMAKE_CXX_FLAGS "-Wall -Werror -std=gnu99 -g")
else ()
    MESSAGE(FATAL_ERROR "gameserver not support platform: ${CMAKE_SYSTEM_NAME}")
endif ()

INCLUDE_DIRECTORIES("${ANET_ROOT}/include")

LINK_DIRECTORIES("${ANET_ROOT}/lib")

if (gameserver)
  ADD_DEFINITIONS(-DPROGRAM=\"${PROGRAM_NAME}\" -DVERSION=\"${VERSION}\")
  ADD_EXECUTABLE(${PROGRAM_NAME} ${GAMESERVER_SRC})
  TARGET_LINK_LIBRARIES(${PROGRAM_NAME} pthread anet)
  INSTALL (TARGETS ${PROGRAM_NAME} RUNTIME DESTINATION bin)
endif()

